package snapex.core.utils;

//import static io.restassured.RestAssured.given;
//import static org.hamcrest.Matchers.notNullValue;
//
//import org.hamcrest.Matcher;
//import org.springframework.core.ParameterizedTypeReference;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.client.RestClientException;
//import org.springframework.web.client.RestTemplate;
//
//import io.restassured.matcher.ResponseAwareMatcher;
//import io.restassured.response.ResponseBody;
//import lombok.AllArgsConstructor;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import snapex.core.model.SearchResult;
//import snapex.expense.model.Expense;
//import snapex.expense.model.ExpenseSearchCondition;

//@Slf4j
public class ExportUtils {

//	public static void main(String[] args) {
//
//		ExportUtils.export();
//	}
//
//	public static SearchResult<Expense> export() {
//
//		AuthroizedExportExpense e = new AuthroizedExportExpense();
//		
//		given().baseUri("http://oauth.snapex.txt").port(8088).auth().basic("snapex-admin", "snapex-admin-secret")
//				.param("grant_type", "client_credentials").param("scope", "openid").when().post("/oauth/token").then()
//				.statusCode(200).body("access_token", e);
//		
//		return e.getExpense();
//	}
//
//	@NoArgsConstructor
//	@AllArgsConstructor
//	@Getter
//	static class AuthroizedExportExpense implements ResponseAwareMatcher {
//
//		private String serviceURL = "http://service.snapex.txt:8090/snapex/expense/export";
//
//		SearchResult<Expense> expense;
//		
//		@Override
//		public Matcher matcher(ResponseBody response) throws Exception {
//			String accessToken = response.path("access_token");
//
//			RestTemplate restTemplate = new RestTemplate();
//			Object responseMsg = "";
//			try {
//				
////				ParameterizedTypeReference<SearchResult<Expense>> searchResult = new ParameterizedTypeReference<SearchResult<Expense>>() {};
//				
//				HttpHeaders requestHeaders = new HttpHeaders();
//				requestHeaders.add("Authorization", "Bearer " + accessToken);	
//				requestHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
//				
//				HttpEntity<ExpenseSearchCondition> requestEntity = new HttpEntity<ExpenseSearchCondition>(new ExpenseSearchCondition(), requestHeaders);
//								
//			    ResponseEntity<SearchResult<Expense>> result = restTemplate.exchange(serviceURL,HttpMethod.POST, requestEntity, new ParameterizedTypeReference<SearchResult<Expense>>() {});
//				
//			    expense = result.getBody();
//			    
//				log.debug("********{}",result.getBody().getItems());
//				
//			} catch (RestClientException e) {
//				responseMsg = e.getMessage();
//				log.error("ERROR", e);
//			}
//
//			return notNullValue();
//		}
//	}
//	
}
